package vader.aspect;//package com.fancy.cc.aspect;
//
//import cn.hutool.core.convert.Convert;
//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
//import com.fancy.cc.mapper.CmsArticleMapper;
//import com.fancy.cc.mapper.CmsOriginArticleMapper;
//import com.fancy.cc.model.CmsArticle;
//import com.fancy.cc.model.CmsOriginArticle;
//import com.fancy.cc.storage.AliyunStorage;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.Aspect;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//
///**
// * @author Vader
// * @date 2021/11/17
// **/
//@Slf4j
//@Aspect
////@Component
//public class originArticleAspect {
//
//    @Resource
//    private AliyunStorage aliyunStorage;
//
//    @Resource
//    private CmsArticleMapper cmsArticleMapper;
//
//    @Resource
//    private CmsOriginArticleMapper originArticleMapper;
//
////    @After(value = "execution(* com.fancy.cc.controller.cms.CmsOriginArticleController.addContent(..))")
//    public void uploadFile(JoinPoint joinPoint) {
//        Object[] args = joinPoint.getArgs();
//        String articleId = String.valueOf(args[0]);
//
//        log.info("上传文章{}的文件", articleId);
////        CmsOriginArticle cmsOriginArticle = originArticleMapper.selectCoentByArticleId(articleId, merchantId);
//
//        String pic = cmsOriginArticle.getPic();
//        String albumPics = cmsOriginArticle.getAlbumPics();
//        String videoSrc = cmsOriginArticle.getUploadVideo();
//        try {
//            //上传资源文件
//            if (StringUtils.isNotBlank(pic)) {
//                String dir = aliyunStorage.uploadFile(pic, articleId + ".jpg");
//                cmsOriginArticle.setPic(dir);
//            }
//            if (StringUtils.isNotBlank(albumPics)) {
//                StringBuilder stringBuilder = new StringBuilder();
//                if (albumPics.contains(",")) {
//                    String[] split = albumPics.split(",");
//                    for (int i = 0, splitLength = split.length; i < splitLength; i++) {
//                        String str = split[i];
//                        String file = aliyunStorage.uploadFile(str, articleId + i + ".jpg");
//                        stringBuilder.append(",");
//                        stringBuilder.append(file);
//                    }
//                    stringBuilder.deleteCharAt(0);
//                } else {
//                    String dir = aliyunStorage.uploadFile(albumPics, articleId + ".jpg");
//                    stringBuilder.append(dir);
//                }
//                cmsOriginArticle.setAlbumPics(stringBuilder.toString());
//            }
//            if (StringUtils.isNotBlank(videoSrc)) {
//                String video = aliyunStorage.uploadFile(videoSrc, articleId + ".mp4");
//                cmsOriginArticle.setVideoSrc(video);
//            }
//            CmsArticle convert = Convert.convert(CmsArticle.class, cmsOriginArticle);
//            cmsArticleMapper.updateByArticleId(convert);
//        } catch (IOException e) {
//            System.out.println(e.getMessage());
//        }
//    }
//}
